#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>

#define MAXDATASIZE 100 /*每次最大数据传输量 */
#define SERVER_IP "192.168.237.118"

int main(void)
{
	int sockfd, recvbytes;
	char buf[MAXDATASIZE];
	//struct hostent *host;
	struct sockaddr_in serv_addr;

	if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
	{
		perror("socket创建出错！");
		exit(1);
	}

	memset(&serv_addr, 0, sizeof(serv_addr));
	serv_addr.sin_family = AF_INET;
	serv_addr.sin_port = 1024;
	serv_addr.sin_addr.s_addr = inet_addr(SERVER_IP);

	if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) == -1)
	{
		perror("connect出错！");
		exit(1);
	}
	if ((recvbytes=recv(sockfd, buf, MAXDATASIZE, 0)) ==-1)
	{
		perror("recv出错！");
		exit(1);
	}
	buf[recvbytes] = '\0';
	printf("Received: %s",buf);
	close(sockfd);
	return 0;
}

